﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi
{
    [CPPEI.WebApi.AuthPostAction("ETL", "Mapping2ExistTable", "1.0")]
    public class Mapping2ExistTableAction : BaseAction<Mapping2ExistTableParams, Mapping2ExistTableResult>
    {
        protected override ActionResult<Mapping2ExistTableResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            Mapping2ExistTableParams opParams)
        {
            SER.MappingService service = new SER.MappingService();
            ServiceResult result = service.Mapping2ExistTable(context.UserId, opParams.ServiceId,
                opParams.SourceId,
                opParams.TableId, opParams.ColumnMapping, opParams.DataIdentity);
            if(result.IsSuccess)
            {
                return new ActionResult<Mapping2ExistTableResult>(new Mapping2ExistTableResult());
            }
            else
            {
                return new ActionResult<Mapping2ExistTableResult>(result.IsSuccess, result.ErrorCode, result.Message, null);
            }
        }
    }

    public class Mapping2ExistTableParams
    {
        [Parameter]
        public Guid TableId { get; set; }

        [Parameter]
        public Guid ServiceId { get; set; }

        [Parameter]
        public Guid SourceId { get; set; }

        /// <summary>
        /// columnid,dtcol-name,dtcol-type,dtcol-length,dtcol-null,
        /// </summary>
        [Parameter]
        public string ColumnMapping { get; set; }

        /// <summary>
        /// columnid,columnid,columnid
        /// </summary>
        [Parameter]
        public string DataIdentity { get; set; }
    }

    public class Mapping2ExistTableResult
    {
    }
}
